#ifndef __THREADSAFE_QUEUE__
#define __THREADSAFE_QUEUE__
#include <iostream>
#include <queue>
#include <mutex>
#include <condition_variable>
#include <memory>

using std::mutex;
using std::condition_variable;
using std::shared_ptr;
using std::queue;

template <typename T>
class threadsafe_queue
{
private:
    mutable mutex _mutex;   //mutable修饰：允许const成员函数修改 满足empty()等锁定互斥
    condition_variable _cond;
    queue<T> _queue;

public:
    threadsafe_queue(){}
    threadsafe_queue(const threadsafe_queue &rhs);
    threadsafe_queue& operator=(const threadsafe_queue &rhs) = delete;

    bool empty() const;
    void push(T new_value);
    void wait_and_pop(T &value);
    shared_ptr<T> wait_and_pop();
    bool try_pop(T &value);
    shared_ptr<T> try_pop();
};

#endif